import {ADD_TO_CARCOUNT, ADD_TO_CARNEW} from './mutations-type'

export default {
  /*进行异步操作  需要在此步进行commit才能修改数据*/
  /* aupdate(context, payload) {
     setTimeout(() => {
       context.commit("update", "ss");
       console.log(payload.mess);
       payload.sussecc("啊哈哈哈");
     }, 1000)
   },*/
  addToCart({state, commit}, oldproduct) {
    return new Promise((resolve, reject) => {
      let product = state.cartList.find(item => item.iid === oldproduct.iid);
      if (product) {
        commit(ADD_TO_CARCOUNT, {product, oldproduct});
        resolve("由于该商品已添加到购物，故数量加：" + oldproduct.count);
      } else {
        commit(ADD_TO_CARNEW, oldproduct);
        resolve("成功添加到购物车!");
      }
    })
  },
}
